Migrate agent tables to network scope (base_prefix)#939
Merged
Conversation
Agent identity, tokens, and access grants are now shared across the multisite network using $wpdb->base_prefix, following the same pattern WordPress uses for wp_users and wp_usermeta. - Add get_table_prefix() to BaseRepository (overridable by child classes) - Agent repos (Agents, AgentTokens, AgentAccess) override to use base_prefix - Add site_scope column to datamachine_agents for per-site agent focus - Migration consolidates per-site agent rows into network table with dedup - Activation creates agent tables once at network level, not per-site - Fix 4 raw $wpdb->prefix references in AgentAbilities and migrations Per-site tables (flows, pipelines, jobs, etc.) are unaffected. Bearer tokens now resolve from a single network table, enabling cross-site agent authentication for external agents like Sarai Chinwag.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Agent identity, tokens, and access grants are now shared across the multisite network using
$wpdb->base_prefix, following the same pattern WordPress uses forwp_usersandwp_usermeta.Agents are an abstraction of users — they must live at the same scope. One user identity, one agent identity, per-site capabilities.
Changes
get_table_prefix()method (defaults to$wpdb->prefix, overridable by child classes)$wpdb->base_prefixsite_scopecolumn ondatamachine_agents— optional blog_id for site-focused agents (NULL = network-wide)datamachine_create_network_agent_tables()$wpdb->prefixreferences in AgentAbilities.php and migrations.phpPer-site tables (flows, pipelines, jobs, chat sessions) are completely unaffected.
Architecture
Mirrors WordPress core:
wp_users(network) +wp_N_posts(per-site).Testing
Tested on production multisite (11 sites):
site_scopecorrectly set per originating blog_idchubesskipped, eventschubesmigrated)get_table_prefix()override only affects agent repos, not othersContext
Enables the Sarai Chinwag external agent test case — a single bearer token will authenticate across any site in the network. Also unblocks network-activating Data Machine in the future.